<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>
<!--弹窗：当天工作时间-->
<div th:fragment="appointimemainTimer" class="modal inmodal fade" id="appointimemainTimer_Modal"
     tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">工作时间</h4>
                <small class="font-bold"></small>
            </div>
            <div class="modal-body">
                <table id="appointimemainTimer_table" class="table table-striped"></table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $(function () {
            appointimemainTimerObj.myTable = $('#appointimemainTimer_table').bootstrapTable({
                method: 'post',
                pagination: true,
                sidePagination: 'server',
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                queryParams: function (param) {
                    return param;
                },
                columns: [{
                    title: '#',
                    align: 'center',
                    width: 50,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                }, {
                    title: '工作时间',
                    field: 'workTime'
                }, {
                    title: '预约人员',
                    field: 'teacherName'
                }, {
                    title: '操作',
                    field: 'action',
                    events: {
                        'click .trash': function (e, value, row, index) {
                            appointimemainTimerObj.deleteHandle(row.id)
                        }
                    },
                    formatter: function (value, row, index) {
                        var opers = [];
                        if(!row.teacherName){
                            opers.push(`<a class="trash btn btn-white btn-bitbucket text-success" data-toggle="tooltip" data-placement="top" title="删除">
                                    <i class="fa fa-trash"></i>
                                </a>`)
                        }
                        return opers.join('');
                    }
                }],
                responseHandler: function (res) {
                    return {
                        total: res.page.totalCount,
                        rows: res.page.list
                    };
                }
            });
        })
        var appointimemainTimerObj = new Object({
            mainId: undefined,
            myTable: undefined,
            init: function (mainId) {
                appointimemainTimerObj.mainId = mainId;
                appointimemainTimerObj.myTable.bootstrapTable('refresh', {
                    url: `/appoin/appointimemain/detail/${mainId}`
                });
                $('#appointimemainTimer_Modal').modal('show')
            },
            refreshDataList: function(){
                appointimemainTimerObj.myTable.bootstrapTable('refresh');
            },
            deleteHandle: function (id) {
                $.mySwalConfirm('将删除工作时间，确认吗？', function () {
                    $.myPost({
                        url: `/appoin/appointimemain/detail/delete`,
                        dataType: 'json',
                        data: [id],
                        success: function (data) {
                            if (data && data.code === 0) {
                                toastr.success(data.msg, '操作提示')
                                appointimemainTimerObj.refreshDataList();
                            } else {
                                toastr.error(data.msg, '操作失败')
                            }
                        }
                    })
                });
            }
        })
    </script>
</div>
</body>
</html>